--解构
local jiegou = fk.CreateSkill {
    name = "mcdh_jiegou",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

jiegou:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(self.name) and target ~= player and target.phase == Player.Discard and #lib.getCanPublicCards(target) > 0 then
            local events = room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                local use = e.data[1]
                return table.contains(TargetGroup:getRealTargets(use.tos),player.id)
            end, Player.HistoryTurn)
            return #events == 1
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        return #lib.askForPublicCard(room,player,target,1,1,self.name,true,"#mcdh_jiegou-public:"..target.id,".",false) ~= 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(target,"#mcdh_jiegou-phase",1)
    end
})

jiegou:addEffect('prohibit',{
    prohibit_discard = function(self, player, card)
        return player:getMark("#mcdh_jiegou-phase") ~= 0 and card:getMark("@@mcdh_overt_card") ~= 0
    end,
})

Fk:loadTranslationTable {
    ["mcdh_jiegou"] = "解构",
    [":mcdh_jiegou"] = "其他角色弃牌阶段开始时，若你本回合成为过牌的目标，你可以明置其一张牌，然后令其本阶段不能弃置明置牌。",
    ["#mcdh_jiegou-public"] = "解构:明置 %src 一张牌，然后令其本阶段不能弃置明置牌。",
}

return jiegou